package com.mindcraft.base.model;

import com.mindcraft.base.utils.CodeMsg;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;


public class MindCraftResult<T> implements Serializable {

    private static final long serialVersionUI = 1L;

    private int code;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getCurrentTimeMillis() {
        return currentTimeMillis;
    }

    public void setCurrentTimeMillis(long currentTimeMillis) {
        this.currentTimeMillis = currentTimeMillis;
    }

    private String message;
    private T data;


    private long currentTimeMillis = System.currentTimeMillis();

    public MindCraftResult() {
        this.code = 200;
    }

    public MindCraftResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public MindCraftResult(int code,String message, T data) {
        this.code =code;
        this.message = message;
        this.data = data;
    }

    public MindCraftResult(T data) {
        this.code = 200;
        this.data = data;
    }

    public MindCraftResult(String message) {
        this.code = 500;
        this.message = message;
    }

    public static <T> MindCraftResult<T> fail(String message) {
        return new MindCraftResult(message);
    }

    public static <T> MindCraftResult<T> fail(CodeMsg codeMsg) {
        return new MindCraftResult(codeMsg.getCode(), codeMsg.getMsg());
    }

    public static <T> MindCraftResult<T> fail(Integer code, String message) {
        return new MindCraftResult(code, message);
    }

    public static <T> MindCraftResult<T> success(T data) {
        return new MindCraftResult(data);
    }

    public static <T> MindCraftResult<T> success() {
        return new MindCraftResult();
    }

    public static <T> MindCraftResult<T> success(int code,String message,T data) {
        return new MindCraftResult(code,message,data);
    }


//    public Map<String, Object> mapresponse(Object dataone,Object datatwo) {
//        Map<String, Object> responseData = new HashMap<>();
//        // ...
//        responseData.put("message", dataone);
//        responseData.put("qqNumberorName", datatwo);
//        return responseData;
//    }
}
